/**
 * @ClassName Offer18
 * @Description TODO
 * @Author clockTown
 * @Date 2021/8/22 19:48
 * @Version 1.0
 */
class Offer18 {
}

/**
 * v0 直接删除
 */
class Offer18V0 {
    public ListNode deleteNode(ListNode head, int val) {
        //设置虚拟头节点，这样就可以不用单独判断删除第一个节点的情况
        ListNode dummy = new ListNode(-1);
        dummy.next = head;
        ListNode cur = dummy;
        while (cur.next != null){
            if (cur.next.val == val){
                cur.next = cur.next.next;
                break;
            }
            cur = cur.next;
        }
        return dummy.next;
    }
}
